package com.gzz.manage.base.customeraddr;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.gzz.common.base.BaseDao;
import com.gzz.common.base.Page;

import lombok.extern.slf4j.Slf4j;

/**
 * @类说明 【收货地址表】数据访问层
 * @author 高振中
 * @date 2021-03-14 00:17:40
 **/
@Slf4j
@Repository
public class CustomerAddrDao extends BaseDao {

	/**
	 * @方法说明 【收货地址表】新增
	 */
	public int save(CustomerAddr vo) {
		StringBuilder sql = new StringBuilder();
		sql.append("INSERT INTO base_customer_addr (id,customerId,name,tel,address,prime)");
		sql.append(" VALUES (?,?,?,?,?,?)");
		Object[] param = { vo.getId(), vo.getCustomerId(), vo.getName(), vo.getTel(), vo.getAddress(), vo.getPrime() };
		// log.info(sql(sql.toString(), param));// 显示SQL语句
		return update(sql.toString(), param);
	}

	/**
	 * @方法说明 【收货地址表】删除
	 */
	public int delete(Object[] ids) {
		String sql = "DELETE FROM base_customer_addr WHERE id IN" + toIn(ids);
		// log.info(sql(sql, ids));// 显示SQL语句
		return update(sql, ids);
	}

	/**
	 * @方法说明 【收货地址表】修改
	 */
	public int update(CustomerAddr vo) {
		StringBuilder sql = new StringBuilder();
		sql.append("UPDATE base_customer_addr SET customerId=?,name=?,tel=?,address=?,prime=?");
		sql.append(" WHERE id=? ");
		Object[] param = { vo.getCustomerId(), vo.getName(), vo.getTel(), vo.getAddress(), vo.getPrime(), vo.getId() };
		// log.info(sql(sql.toString(), param));// 显示SQL语句
		return update(sql.toString(), param);
	}

	/**
	 * @方法说明 【收货地址表】分页列表
	 */
	public Page<CustomerAddr> page(CustomerAddrCond cond) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT t.id,t.customerId,t.name,t.tel,t.address,t.prime");
		sql.append(" FROM base_customer_addr t");
		sql.append(cond.where());
		log.info(sql(sql.toString(), cond.array()));// 显示SQL语句
		return page(sql.toString(), cond, CustomerAddr.class);
	}

	/**
	 * @方法说明 【收货地址表】列表
	 */
	public List<CustomerAddr> list(CustomerAddrCond cond) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT t.id,t.customerId,t.name,t.tel,t.address,t.prime");
		sql.append(" FROM base_customer_addr t");
		sql.append(cond.where());
		sql.append(" ORDER BY id DESC");
		// log.info(sql(sql.toString(),cond.array()));//显示SQL语句
		return list(sql.toString(), cond, CustomerAddr.class);
	}

	/**
	 * @方法说明 【收货地址表】按主键查
	 */
	public CustomerAddr findById(Integer id) {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT t.id,t.customerId,t.name,t.tel,t.address,t.prime");
		sql.append(" FROM base_customer_addr t WHERE t.id=?");
		// log.info(sql(sql.toString(),id));//显示SQL语句
		return findById(sql.toString(), CustomerAddr.class, id);
	}

	/**
	 * @方法说明 【收货地址表】个数
	 */
	public int count(CustomerAddrCond cond) {
		String sql = "SELECT COUNT(1) FROM base_customer_addr t " + cond.where();
		// log.info(sql(sql,cond.array()));//显示SQL语句
		return count(sql, cond);
	}

	/**
	 * @方法说明 【收货地址表】新增并返回自增涨主键
	 */
	public int saveReturnPK(CustomerAddr vo) {
		StringBuilder sql = new StringBuilder();
		sql.append("INSERT INTO base_customer_addr (id,customerId,name,tel,address,prime)");
		sql.append(" VALUES (:id,:customerId,:name,:tel,:address,:prime)");
		// log.info(sqlp(sql.toString(), vo));// 显示SQL语句
		return saveKey(vo, sql.toString(), "id");
	}

	/**
	 * @方法说明 【收货地址表】批量插入
	 */
	public int[] insertBatch(List<CustomerAddr> list) {
		StringBuilder sql = new StringBuilder();
		sql.append("INSERT INTO base_customer_addr (id,customerId,name,tel,address,prime)");
		sql.append(" VALUES (:id,:customerId,:name,:tel,:address,:prime)");
		// log.info(sqlp(sql.toString(), list));// 显示SQL语句
		return batchOperate(list, sql.toString());
	}

	/**
	 * @方法说明 【收货地址表】批量更新
	 */
	public int[] updateBatch(List<CustomerAddr> list) {
		StringBuilder sql = new StringBuilder();
		sql.append("UPDATE base_customer_addr SET id=:id,customerId=:customerId,name=:name,tel=:tel,address=:address,prime=:prime");
		sql.append(" WHERE id=:id ");
		// log.info(sqlp(sql.toString(), list));// 显示SQL语句
		return batchOperate(list, sql.toString());
	}
	/**
	 * @方法说明 【收货地址表】逻辑删除
	 */
//	public int delete(Object... ids) {
//		String sql = "UPDATE base_customer_addr SET dr=1 WHERE id IN " + toIn(ids);
//		return update(sql,ids);
//	}	

}